import com.powerfl.frm.taf.*;

final public function INT( $val:* ):int{
	if( $val is int ){
		return $val;
	}else{
		return int($val);
	}
}
final public function UINT( $val:* ):int{
	if( $val is uint ){
		return $val;
	}else{
		return uint($val);
	}
}
final public function NUM( $val:* ):int{
	if( $val is Number ){
		return $val;
	}else{
		return Number($val);
	}
}
final public function STR( $val:* ):int{
	if( $val is String ){
		return $val;
	}else{
		return $val.toString();
	}
}
final public function plus( $original:*, ...$val ):*{
	var result:*, i:int, j:int;
	result = $original;
	if( result is Array ){
		for( i = 0, j = $val.length ; i < j ; ++i ){
			if( $val[i] is Array ){
				if( $val[i].length ){
					result = result.concat( $val[i] );
				}
			}else{
				result[result.length] = $val[i];
			}
		}
	}else{
		for( i = 0, j = $val.length ; i < j ; ++i ){
			result += $val[i];
		}
	}
	return result;
}
final public function minus( $original:*, ...$val ):*{
	var result:*, i:int, j:int, k:int, l:int, m:int;
	result = $original;
	if( result is Array ){
		for( i = 0, j = $val.length ; i < j ; ++i ){
			if( $val[i] is Array ){
				l = $val[i].length;
				if( l ){
					for( k = 0 ; k < l ; ++k ){
						m = result.indexOf( $val[i][k] );
						if( m > -1 ){
							result.splice( m, 1 );
						}
					}
				}
			}else{
				m = result.indexOf( $val[i] );
				if( m > -1 ){
					result.splice( m, 1 );
				}
			}
		}
	}else if( result is String ){
		for( i = 0, j = $val.length ; i < j ; ++i ){
			result = result.replace( $val[i], '' ); 
		}
	}else{
		for( i = 0, j = $val.length ; i < j ; ++i ){
			result -= $val[i];
		}
	}
	return result;
}
final public function not( $a:*, $b:*, ...$flows ):*{
	return operatorConditional( $a !== $b, $flows );
}
final public function equal( $a:*, $b:*, ...$flows ):*{
	return operatorConditional( $a === $b, $flows );
}
private function operatorFlowGet( $condition:* ):*{
	var flow:*;
	if( $condition is Array ){
		flow = $condition[0];
		if( flow is String ){
			flow = flowGet( flow );	
		}
		if( $condition.length > 1 ){
			return flow.apply( null, $condition.slice( 1 ) );
		}else{
			return flow();
		}
	}else{
		return $condition; 
	}
}
private function operatorConditional( $condition:Boolean, $flows:Array ):*{
	if( $condition ){
		if( $flows.length > 0 ){
			return operatorFlowGet( $flows[0] );
		}
	}else{
		if( $flows.length > 1 ){
			return operatorFlowGet( $flows[1] );
		}
	}
	return $condition;
}